package com.asset.dispoal.business.bsAgreement;

import com.asset.dispoal.business.bsAgreement.api.BsAgreementService;
import com.asset.dispoal.business.bsAgreement.dto.AgreementDataRequest;
import com.asset.dispoal.business.bsAgreement.dto.AgreementDataResponse;
import com.asset.dispoal.business.bsAgreement.dto.AgreementRequest;
import com.asset.dispoal.business.bsAgreement.dto.AgreementResponse;
import com.asset.dispoal.business.bsAgreement.dto.EvidenceDataRequest;
import com.asset.dispoal.business.bsAgreement.dto.MergeDownloadRequest;
import com.asset.dispoal.business.bsAgreement.dto.MergeDownloadResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.controller.BaseController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @author qr
 * @date 2022/4/11$
 */

@RestController
@RequestMapping("business/bsAgreement")
@Api(value = "合同管理", tags = "合同管理")
public class BsAgreementController extends BaseController {

    @Autowired
    BsAgreementService bsAgreementService;


    @GetMapping(value = "/queryAgreement")
    @ApiOperation(value = "借款人合同根据案件分组分页查询", notes = "借款人合同根据案件分组分页查询")
    public Result<List<AgreementResponse>> queryAgreement(AgreementRequest agreementRequest) {
        return bsAgreementService.queryAgreement(agreementRequest);
    }


    @GetMapping(value = "/queryAgreementData")
    @ApiOperation(value = "根据合同id查询合同详情", notes = "根据合同id查询合同详情")
    public Result<AgreementDataResponse> queryAgreementData(String agreementId) {
        AgreementDataResponse agreementDataResponse = bsAgreementService.queryAgreementData(agreementId);
        return Result.ok(agreementDataResponse);
    }


    @PostMapping(value = "/updateAgreementData")
    @ApiOperation(value = "根据合同id修改合同信息", notes = "根据合同id修改合同信息")
    public Result updateAgreementData(@RequestBody AgreementDataRequest agreementDataRequest) {
        return bsAgreementService.updateAgreementData(agreementDataRequest);
    }

    @Permission(code = "contractContractevidence:query", param = "agreement.create_user")
    @GetMapping(value = "/queryEvidenceDataPage")
    @ApiOperation(value = "证据查阅", notes = "证据查阅")
    public Result<PageVO<AgreementResponse>> queryEvidenceDataPage(EvidenceDataRequest request) {
        return bsAgreementService.queryEvidenceDataPage(request);
    }

    @Permission(code = "contractWasteCase:query", param = "agreement.create_user")
    @GetMapping(value = "/caseTracking")
    @ApiOperation(value = "案件追踪", notes = "案件追踪")
    public Result<PageVO<AgreementResponse>> caseTracking(AgreementDataRequest agreementRequest) {
        return bsAgreementService.caseTracking(agreementRequest);
    }

    @GetMapping(value = "wasteCase")
    @ApiOperation(value = "废案", notes = "废案")
    public Result wasteCase(String agreementId, String wasteReasonId) {
        return bsAgreementService.abolishCase(agreementId, wasteReasonId);
    }

    @GetMapping(value = "resumeState")
    @ApiOperation(value = "状态恢复", notes = "状态恢复")
    public Result resumeState(String agreementId) {
        return bsAgreementService.resumeState(agreementId);
    }

    @GetMapping(value = "caseClose")
    @ApiOperation(value = "结案", notes = "结案")
    public Result caseClose(String agreementId) {
        return bsAgreementService.caseClose(agreementId);
    }

    @GetMapping(value = "/queryMergeDownload")
    @ApiOperation(value = "查询打包历史", notes = "打包历史")
    public Result<PageVO<MergeDownloadResponse>> queryMergeDownload(MergeDownloadRequest request) {
        return bsAgreementService.queryMergeDownload(request);
    }
}